<template>
  <div class="content content52">
    <div>检测条件：温度T：<el-input v-model="form.temperature" class="input-line" />℃；气压p：<el-input v-model="form.pressure" class="input-line" />Kpa</div>
    <div class="innertitle">
      1.输出量偏差：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>照射野，cm</td>
        <td>SDD,cm</td>
        <td>SSD,cm</td>
        <td>预置值<i>$D_0$</i>，cGy</td>
        <td>输出剂量率，cGy/min</td>
        <td>校准因子<i>$N_k$</i></td>
      </tr>
      <tr>
        <td><el-input v-model="form.outputDeviation.irradiationField" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation.sdd" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation.ssd" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation.presetValue" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation.outputDoseRate" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation.calibrationFactor" class="input-line" /></td>
      </tr>
    </table>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td rowspan="2">管电压<br/>kV</td>
        <td rowspan="2">管电流<br/>mA</td>
        <td rowspan="2">参考点深度<br/>s，cm</td>
        <td rowspan="2">PDDs<br/>%</td>
        <td :colspan="outputDeviation.table.td">仪器读数Mu，cGy</td>
        <td rowspan="2">校准值<i>$D_1$</i><br/>cGy</td>
        <td rowspan="2">输出量偏差B<br/>%</td>
      </tr>
      <tr>
        <td v-for="index in outputDeviation.table.td" :key="index">{{index}}</td>
      </tr>
      <tr v-for="trIndex in outputDeviation.table.tr" :key="trIndex">
        <td><el-input v-model="form.outputDeviation['tubeVoltage_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation['tubeCurrent_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation['depth_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation['pdd_'+trIndex]" class="input-line" /></td>
        <td v-for="tdIndex in outputDeviation.table.td" :key="tdIndex"><el-input v-model="form.outputDeviation['readoutValue_'+trIndex+'_'+tdIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation['calibrationValue_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputDeviation['deviation_'+trIndex]" class="input-line" /></td>
      </tr>
    </table>
    <div>
      对于高能X射线（300kV～1MV）：<i>$D_{1}= \frac {\overline{M_u}\times{N_{D,air}}\times{S_{w,air}}\times{P_{wall}}\times{P_{cav}}\times{P_{cel}}}{PDD_S}$</i>
      ，&nbsp;&nbsp;<i>$N_{D,air} =  N_k(1-g)k_{att}k_mk_{cel}$</i>
      ，&nbsp;&nbsp;<i>$P_{wall} = \frac {\alpha \times S_{wall,air} \times (\mu_{en} / \rho )_{w,wall} + (1 - \alpha) \times S_{W,air}}{S_{W,air}}$</i><br/><span style="margin-left: 100px;"></span>
      ，&nbsp;&nbsp;<i>$TPR_{(20,10)} = 2.1891 - 1.30756 {\frac {1}{PDD_{20,10}}} + 0.24915 ({\frac {1}{PDD_{20,10}})^2}$</i>
    </div>
    <div>
      对于中能X射线（100kV～300kV）：<i>$D_1 = \overline {M_u} \times N_k \times (\overline {\mu_{en}} / \rho)_{w,air} \times P_u$</i>
      ，&nbsp;&nbsp;<i>$B = \frac {D_1 - D_0}{D_0} \times 100\%$</i>
    </div>
    <div>
      对于低能X射线（10kV～100kV）：<i>$D_1 = \overline {M_u} \times N_k \times B \times K_u \times (\overline {\mu_{en}} / \rho)_{w,air}$</i>
    </div>
    <div class="innertitle">
      2.输出量重复性：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>照射野，cm</td>
        <td>SDD,cm</td>
        <td>SSD,cm</td>
        <td>预置值<i>$D_0$</i>，cGy</td>
        <td>输出剂量率，cGy/min</td>
      </tr>
      <tr>
        <td><el-input v-model="form.outputRepeatability.irradiationField" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability.sdd" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability.ssd" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability.presetValue" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability.outputDoseRate" class="input-line" /></td>
      </tr>
    </table>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td rowspan="2">管电压<br/>kV</td>
        <td rowspan="2">管电流<br/>mA</td>
        <td :colspan="outputRepeatability.table.td">仪器读数<i>$K_i$</i>，cGy</td>
        <td rowspan="2">重复性偏差CV<br/>%</td>
      </tr>
      <tr>
        <td v-for="index in outputRepeatability.table.td" :key="index">{{index}}</td>
      </tr>
      <tr v-for="trIndex in outputRepeatability.table.tr" :key="trIndex">
        <td><el-input v-model="form.outputRepeatability['tubeVoltage_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability['tubeCurrent_'+trIndex]" class="input-line" /></td>
        <td v-for="tdIndex in outputRepeatability.table.td" :key="tdIndex"><el-input v-model="form.outputRepeatability['readoutValue_'+tdIndex+'_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.outputRepeatability['repeatabilityDeviation_'+trIndex]" class="input-line" /></td>
      </tr>
    </table>
    <div>备注：输出量重复性和线性应在以下两种条件下检测：1)标称X射线管电压下；2)大约标称X射线管电压的50%或规定的最低X射线管电压下取两者之中较高值。</div>
    <div><i>$CV = \frac {1}{\overline K_i} \sqrt {\Sigma (K_i - \overline {K_i})^2 / 9 } \times 100\% $</i></div>
    <div class="innertitle">
      3.输出量线性：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td rowspan="2">照射野，cm</td>
        <td rowspan="2">SDD,cm</td>
        <td rowspan="2">SSD,cm</td>
        <td rowspan="2">输出剂量率，cGy/min</td>
        <td colspan="2">累积剂量预设值，cGy</td>
      </tr>
      <tr>
        <td>0.05满度值</td>
        <td>0.2满度值</td>
      </tr>
      <tr>
        <td><el-input v-model="form.outputLinearity.irradiationField" class="input-line" /></td>
        <td><el-input v-model="form.outputLinearity.sdd" class="input-line" /></td>
        <td><el-input v-model="form.outputLinearity.ssd" class="input-line" /></td>
        <td><el-input v-model="form.outputLinearity.outputDoseRate" class="input-line" /></td>
        <td><el-input v-model="form.outputLinearity.fullScaleValue_1" class="input-line" /></td>
        <td><el-input v-model="form.outputLinearity.fullScaleValue_2" class="input-line" /></td>
      </tr>
    </table>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td rowspan="2">管电压<br/>kV</td>
        <td rowspan="2">管电流<br/>mA</td>
        <td rowspan="2">序号</td>
        <td rowspan="2">输出量预设值<i>$Q_i$</i><br/>cGy</td>
        <td :colspan="outputLinearity.table.td">仪器读数<i>$K_i$</i>，cGy</td>
        <td rowspan="2">相对比值<br/>Mi</td>
        <td rowspan="2">输出量线性<i>$L_i$</i><br/>%</td>
      </tr>
      <tr>
        <td v-for="index in outputLinearity.table.td" :key="index">{{index}}</td>
      </tr>
      <tbody v-for="tbodyIndex in outputLinearity.table.tbody" :key="tbodyIndex">
        <tr v-for="trIndex in outputLinearity.table.tr" :key="trIndex">
          <td v-if="trIndex == 1" :rowspan="outputLinearity.table.tr"><el-input v-model="form.outputLinearity['tubeVoltage_'+tbodyIndex]" class="input-line" /></td>
          <td v-if="trIndex == 1" :rowspan="outputLinearity.table.tr"><el-input v-model="form.outputLinearity['tubeCurrent_'+tbodyIndex]" class="input-line" /></td>
          <td>{{(tbodyIndex-1)*outputLinearity.table.tr + trIndex}}</td>
          <td><el-input v-model="form.outputLinearity['presetsValue_1_'+((tbodyIndex-1)*outputLinearity.table.tr + trIndex)]" class="input-line" /></td>
          <td v-for="tdIndex in outputLinearity.table.td" :key="tdIndex"><el-input v-model="form.outputLinearity['readoutValue_'+((tbodyIndex-1)*outputLinearity.table.tr + trIndex)+'_'+tdIndex]" class="input-line" /></td>
          <td><el-input v-model="form.outputLinearity['relativeRatio_'+((tbodyIndex-1)*outputLinearity.table.tr + trIndex)]" class="input-line" /></td>
          <td v-if="trIndex == 1"  :rowspan="outputLinearity.table.tr"><el-input v-model="form.outputLinearity['outputLinearity_'+ tbodyIndex]" class="input-line" /></td>
        </tr>
      </tbody>
    </table>
    <div>
      <i>$M_i = \frac {\overline K_i}{Q_i}$</i>
      ，&nbsp;&nbsp;<i>$L_1 = \frac {|M_1- M_2|}{|M_1 + M_2|}$</i>
      ，&nbsp;&nbsp;<i>$L_2 = \frac {|M_3- M_4|}{|M_3 + M_4|}$</i>
    </div>
    <div class="innertitle">
      4.泄漏辐射：（仅验收检测本项目）
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>X射线管额定管电压<br/>（kV）</td>
        <td>X射线管管电流<br/>（mA）</td>
        <td>采用屏蔽材料</td>
        <td>厚度</td>
      </tr>
      <tr>
        <td><el-input v-model="form.leakageRadiation.tubeVoltage" class="input-line" /></td>
        <td><el-input v-model="form.leakageRadiation.tubeCurrent" class="input-line" /></td>
        <td><el-input v-model="form.leakageRadiation.shieldingMaterial" class="input-line" /></td>
        <td><el-input v-model="form.leakageRadiation.thickness" class="input-line" /></td>
      </tr>
    </table>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td rowspan="2">编号</td>
        <td rowspan="2">夹角<br/>（°）</td>
        <td :colspan="leakageRadiation.table.td">读数<i>$K_i$</i>，（<el-select v-model="form.leakageRadiation.readoutValueUnit" placeholder="请选择">
            <el-option
              v-for="item in [{value:1,label:'mGy/h'}]"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>）</td>
        <td rowspan="2">修正值(mGy/h)</td>
        <td rowspan="2">备注</td>
      </tr>
      <tr>
        <td v-for="tdIndex in leakageRadiation.table.td" :key="tdIndex">{{tdIndex}}</td>
      </tr>
      <tr v-for="trIndex in leakageRadiation.table.tr" :key="trIndex">
        <td><el-input v-model="form.leakageRadiation['rowsNumber_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.leakageRadiation['includedAngle_'+trIndex]"class="input-line" /></td>
        <td v-for="tdIndex in leakageRadiation.table.td" :key="tdIndex">
          <el-input v-model="form.leakageRadiation['readoutValue_'+trIndex+'_'+tdIndex]" class="input-line" />
        </td>
        <td><el-input v-model="form.leakageRadiation['correctedValue_'+trIndex]" class="input-line" /></td>
        <td style="min-width: 120px;"><el-input v-model="form.leakageRadiation['remark_'+trIndex]" class="input-line" /></td>
      </tr>
    </table>
  </div>
</template>

<script>
  import {getInfoById, postInfo} from '@/api/testItem/item52'
  export default{
    name:'testItem52',
    props: {
    	// tab栏
      activeNameEquipment: {
    		type: String,
        default: "0",
      },
    	// 基本信息数据
      basicForm: {
    		type: Object,
        default: () => {
    			return {}
    		},
      },
    },
    data(){
      return {
        "sdd": {
          action:'saveInfo',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false
        },
        "outputDeviation": {
          action:'deviation',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            td:5,
            tr:4
          }
        },
        "outputRepeatability": {
          action:'repeatability',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            td:10,
            tr:2
          }
        },
        "outputLinearity": {
          action:'linearity',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            td:5,
            tr:2,
            tbody:2
          }
        },
        "leakageRadiation": {
          action:'radiation',
          flag:true,
          loading:false,
          notNumber:['shieldingMaterial','readoutValueUnit','remark'],
          intNumber:['rowsNumber'],
          like:true,
          table:{
            td:3,
            tr:38
          }
        },
        "form": {
          "itemsId": 0,
          "resultId": 0,
          "temperature": 0.0,
          "pressure": 0.0,
          "outputDeviation": {
            "itemsId": 0
          },
          "outputRepeatability": {
            "itemsId": 0
          },
          "outputLinearity": {
            "itemsId": 0
          },
          "leakageRadiation": {
            "itemsId": 0
          }
        }
      }
    },
    watch:{
      activeNameEquipment: {
        handler(val) {
          this.$nextTick(()=>{
            let resultId = this.basicForm.resultId;
            getInfoById(resultId).then(response => {
              if(response.code == 200){
                let data = response.data;
                for(let keys in data){
                  this.setData(keys,data[keys]);
                }
                this.setStaticData();
                 setTimeout(()=>{
                   this.initFlag = true;
                 },300)
              }
            }).catch((response) => {
               this.$emit("loadingchange", true);
             });
             });
        },
        deep: true,
        immediate: true
      },
      "form.outputDeviation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'outputDeviation');
         }
        },
        deep:true,
        immediate: true
      },
      "form.outputRepeatability":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'outputRepeatability');
         }
        },
        deep:true,
        immediate: true
      },
      "form.outputLinearity":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'outputLinearity');
         }
        },
        deep:true,
        immediate: true
      },
      "form.leakageRadiation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'leakageRadiation');
         }
        },
        deep:true,
        immediate: true
      },
      "form.temperature":{
          handler(newName, oldName) {
            if(this.initFlag){
             this.validateData(this.form,'sdd');
            }
          },
          immediate: true
        },
      "form.pressure":{
        handler(newName, oldName) {
          if(this.initFlag){
           this.validateData(this.form,'sdd');
          }
        },
        immediate: true
      },
    },
    methods:{
      setStaticData(){
        let body = ['距X射线源组件表面5cm','距X射线源组件表面100cm'];
        let tr = ['0','45','90','135','180','225','270','315'];
        let num = 0;
        body.forEach((bi,bk)=>{
          tr.forEach((tri,trk)=>{
            num = bk * tr.length + trk + 1;
            this.form.leakageRadiation['includedAngle_'+num] = tri;
            this.form.leakageRadiation['remark_'+num] = bi;
          })
        })
      },
      //修改数据
      setData(name,data){
        this.form[name] = data ? data : (this[name] ? {}:null);
      },
      //表单修改提交后端
       postForm(param,name){
         param['itemsId'] = this.form.itemsId;
         this.$emit("loadingchange", true);
      	 postInfo(param,this[name].action).then(res=>{
      		 this.$emit("loadingchange", false);
      		 if(res.code == 200){
      			 this[name].flag = false;
      			 if(name != 'sdd'){
      				this.setData(name,res.data);
      			 }
      		 }
      	 })
      },
      validateType(arr,keys,obj){
      	if(obj.like){
      		for(let i=0;i<arr.length;i++){
      			if(keys.indexOf(arr[i]) != -1){
      				return true;
      			}
      		}
      		return false;
      	}else{
      		if(arr.indexOf(keys) != -1){
      			return true;
      		}
      		return false;
      	}
      },
       //数据验证
       validateData(newName,myName){
      	 if(!this[myName].noClear){
      		clearTimeout(this[myName].loading);
      	 }else{
      		 this[myName].noClear = false;
      	 }
         let regNumber = /^[-]?\d*([.](\d+))?$/;//小数验证正则
         let regRepNumber = /[^-?\d.,]/g;//将除小数外的符号消除正则
         let regInt = /^\d*$/;//整数验证正则
         let regRepInt = /[^-?\d,]/g;//将除小数外的符号消除正则
         let reg,regRep;
         let repStr = '';
      	 let intResult
         if(JSON.stringify(newName) != '{}'){
           //遍历该对象所有字段进行验证
           for(let keys in newName){
             //数字验证环节
      			 if((typeof newName[keys] == 'string') ||  (typeof newName[keys] == 'number')){
      				if(newName[keys] && !this.validateType(this[myName].notNumber,keys,this[myName])){
      					intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      					reg = intResult ? regInt:regNumber;
      				  let bool = !reg.test(newName[keys]);
      				  if(bool){
      						setTimeout(()=>{
      							intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      							regRep = intResult ? regRepInt:regRepNumber;
      									repStr = newName[keys] + '';
      							repStr =  repStr.replace(regRep,'');
      							if(repStr != (newName[keys]+'')){
      								if(!this[myName].noClear){
      									this[myName].noClear = true;
      								}
      								newName[keys] = repStr;
      							}
      						},100);
      						if(this[myName].flag){
      						 this[myName].flag = false;//如果数字验证不通过不需要请求后端
      						}
      				  }
      				}
      			 }
           }
      		 this.isPost(newName,myName);
         }
       },
       isPost(newName,myName){
      	 if(this[myName].flag){//是否请求后端判断
      	  let postBody = {};
      	  for(let i in newName){
      	    if(newName[i] !== null && newName[i] !== undefined){
      	      postBody[i] = newName[i];
      	    }
      	  }
      	  if(JSON.stringify(postBody) != '{}'){
      			this[myName].loading = setTimeout(()=>{
      				this.postForm(postBody,myName);
      			},800)
      	  }
      	 }else{
      		 this[myName].flag = true;
      	 }
       },
    },
  }
</script>

<style lang="scss" scoped>
  @import '../content.scss';

  .miniFont {
    font-size: 10px;
  }

  .miniFontCenter {
    margin-top: 8px;
  }

  .content52 {
    padding-inline: 0 !important;

    table {
      width: 100%;

      td {
        max-width: 100px;

        ::v-deep .el-checkbox__label {
          white-space: break-spaces;
        }
      }

      .el-input {
        width: 100% !important;
      }

      .multipleInput {
        .el-input {
          width: 50px !important;
        }
      }
    }

    .innertitle {
      display: block;
      margin-left: 0;
    }

    .table1 {
      .el-radio {
        display: flex;
        align-items: center;
      }
    }

    #hearderTR td:nth-child(7) {
      display: none;
    }
  }
</style>
